/* 
 * File:   Point.c
 * Author: Muhammad Anis
 */

#include "Point.h"

/**
 * Create Point from given (x,y)
 * @param x X Coordinate
 * @param y Y Coordinate
 */
Point MakePoint(double x, double y) {
    Point p;
    SetAbsis(&p, x);
    SetOrdinat(&p, y);
    return p;
}

/**
 * I.S : Independent
 * F.S : Write Point Value to screen
 * @param p Given Point
 */
void PrintPoint(Point p) {
    printf("Koordinat x: %d Koordinat y: %d\n", p.x, p.y);
}

/**
 * I.S : Independent
 * F.S : P is moved to x+deltaX and y+deltaY
 * @param p Given Point
 */
void Move(Point* p, double deltaX, double deltaY) {
    SetAbsis(p, GetAbsis(*p) + deltaX);
    SetOrdinat(p, GetOrdinat(*p) + deltaY);
}

/**
 * Check if a point is less than other point
 * A point is less than other if P1.x < P2.x && P1.y<P2.y
 * @param p1 First point
 * @param p2 Second point
 * @return true jika p1 < p2
 */
double isLessThan(Point p1, Point p2) {
    return (p1.x < p2.x && p2.y < p2.y);
}

/**
 * Check if a point is on its origin
 * @param p Given point
 * @return true if coordinate of p is (0,0)
 */
double isOrigin(Point p) {
    return (p.x == 0 && p.y == 0);
}
/**
 * Get Absis Part of given point
 * @param p Given Point
 * @return Absis of point
 */
double GetAbsis(Point p) {
    return p.x;
}
/**
 * Get Y Part of given Point
 * @param P Given point
 * @return Ordinat of a Point
 */
double GetOrdinat(Point p) {
    return p.y;
}
/**
 * I.S : Independent
 * F.S : Absis of P value is set to x
 * @param p Given Point
 * @param x New Absis value
 */
void SetAbsis(Point* p, double x) {
    p->x = x;
}
/**
 * I.S : Independent
 * F.S : Ordinat of P value is set to y
 * @param p Given Point
 * @param y new Ordinat value
 */
void SetOrdinat(Point *p, double y) {
    p->y = y;
}
/**
 * Check if a point is equal with another point
 * @param p1 First point
 * @param p2 Second point
 * @return true if P1.x = P2.x && P1.x = P2.x
 */
double EqPoint(Point p1, Point p2) {
    return (p1.x == p2.x && p1.y == p2.y);
}
/**
 * Move Point to its mirror position
 * @param p Given Point
 * @return Point which has coordinate as result of p point mirror
 */
Point Mirrorof(Point p) {
    Point ret;
    SetAbsis(&ret, -p.x);
    SetOrdinat(&ret, -p.y);
    return ret;
}
/**
 * I.S : Independent
 * F.S : Move p to mirror Position
 * @param p Given Point
 */
void MirroringPoint(Point* p) {
    SetAbsis(p, -p->x);
    SetOrdinat(p, -p->y);
}




